package com.vca.admin.controller;

import com.vca.common.page.CommonPage;
import com.vca.common.request.ExhibitionAddRequest;
import com.vca.common.request.PageParamRequest;
import com.vca.common.request.AdminCommonRequest;
import com.vca.common.request.TalkAddRequest;
import com.vca.common.response.AdminHeaderResponse;
import com.vca.common.response.ExhibitionAdminListResponse;
import com.vca.common.response.ExhibitionAdminResponse;
import com.vca.common.response.TalkAdminResponse;
import com.vca.common.result.CommonResult;
import com.vca.service.service.ExhibitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 展览控制器
 *
 * @author Li
 * @date 2022/11/14   13:15
 */
@Slf4j
@RestController("ExhibitionController")
@RequestMapping("api/admin/exhibition")
@Api(tags = "展览控制器")
public class ExhibitionController {

    @Autowired
    private ExhibitionService exhibitionService;

    /**
     * 课程管理
     * @param request
     * @param pageParamRequest
     * @author Li
     * @date    2022/11/11 13:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:list')")
    @ApiOperation("展览管理")
    @GetMapping("/list")
    public CommonResult<CommonPage<ExhibitionAdminListResponse>> getList(@ModelAttribute @Validated AdminCommonRequest request, @ModelAttribute PageParamRequest pageParamRequest){
        CommonPage commonPage = CommonPage.restPage(exhibitionService.getAdminList(request,pageParamRequest));
        return CommonResult.success(commonPage);
    }

    /**
     * 修改排序
     * @param exhibitionId 展览id
     * @param sort 排序
     * @author Li
     * @date    2022/11/21 10:12
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:update:sort')")
    @ApiOperation("修改排序")
    @GetMapping("/updateSort")
    public CommonResult updateSort(Integer exhibitionId,Integer sort){
        return exhibitionService.updateSort(exhibitionId,sort)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 修改限量
     * @param exhibitionId 展览id
     * @param seatCount 限量
     * @author Li
     * @date    2022/11/21 10:12
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:update:quota')")
    @ApiOperation("修改限量")
    @GetMapping("/updateSeatCount")
    public CommonResult updateSeatCount(Integer exhibitionId,Integer seatCount){
        return exhibitionService.updateSeatCount(exhibitionId,seatCount)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 上架展览
     * @param exhibitionId 展览id
     * @author Li
     * @date    2022/11/21 10:12
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:shell:on')")
    @ApiOperation("上架展览")
    @GetMapping("/courseOnShell")
    public CommonResult courseOnShell(Integer exhibitionId){
        return exhibitionService.courseOnShell(exhibitionId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 下架展览
     * @param exhibitionId 展览id
     * @author Li
     * @date    2022/11/21 10:12
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:shell:off')")
    @ApiOperation("下架展览")
    @GetMapping("/courseOffShell")
    public CommonResult courseOffShell(Integer exhibitionId){
        return exhibitionService.courseOffShell(exhibitionId)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 添加展览
     * @param request
     * @author Li
     * @date 2022/11/21 10:12
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:add')")
    @ApiOperation("添加展览")
    @PostMapping("/add")
    public CommonResult addTalk(@RequestBody ExhibitionAddRequest request){
        return exhibitionService.addTalk(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 根据id获取展览信息
     * @param exhibitionId
     * @author Li
     * @date    2022/11/22 10:25
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:get')")
    @ApiOperation("根据id获取展览信息")
    @GetMapping("/getTalk")
    public CommonResult<ExhibitionAdminResponse> getTalk(Long exhibitionId){
        return CommonResult.success(exhibitionService.getTalk(exhibitionId));
    }

    /**
     * @Description:修改展览
     * @Author: Li
     * @Date: 2022/11/22 14:56
     */
    @PreAuthorize("hasAuthority('admin:exhibition:update')")
    @ApiOperation(value = "修改展览")
    @PostMapping("/update")
    public CommonResult<String> update(@RequestBody ExhibitionAddRequest request) {
        return exhibitionService.updateTalk(request)?CommonResult.success():CommonResult.failed();
    }

    /**
     * 获得展览头部数据
     * @author Li
     * @date 2022/11/23 09:16
     * @return
     */
    @ApiOperation(value = "获得展览头部数据")
    @GetMapping("/header")
    public CommonResult<List<AdminHeaderResponse>> getHeader() {
        return CommonResult.success(exhibitionService.getHeader());
    }

    /**
     * 删除展览
     * @author Li
     * @date 2022/11/23 09:16
     * @return
     */
    @PreAuthorize("hasAuthority('admin:exhibition:delete')")
    @ApiOperation(value = "删除展览")
    @GetMapping("/delete")
    public CommonResult delete(Long exhibitionId){
        return exhibitionService.deleteTalk(exhibitionId)?CommonResult.success():CommonResult.failed();
    }
}
